package com.example.composedialogdemo.dialog

import android.R.attr.text
import androidx.compose.foundation.horizontalScroll
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.OutlinedCard
import androidx.compose.material3.OutlinedTextField
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.Dialog

/**
 * @author: njb
 * @date:   2025/8/16 21:46
 * @desc:   描述
 */
@Composable
fun InputDialogExample(
    showDialog: Boolean,
    onDismiss:() -> Unit,
    onConfirm: (String) -> Unit
){
    var text by remember { mutableStateOf("") }
    if(showDialog){
        Dialog(onDismissRequest = onDismiss) {
            Surface(
                shape = MaterialTheme.shapes.medium,
                color = MaterialTheme.colorScheme.surface,
            ){
                Column(modifier = Modifier.padding(16.dp)) {
                    Text(
                        text = "请输入内容",
                        style = MaterialTheme.typography.headlineSmall,
                    )
                    Spacer(modifier = Modifier.height(16.dp))
                    OutlinedTextField(
                        value = text,
                        onValueChange = { text= it},
                        label = {Text("请输入内容")},
                        modifier = Modifier.fillMaxWidth()
                    )
                    Spacer(modifier = Modifier.height(24.dp))
                    Row (
                        modifier = Modifier.align(Alignment.End),
                        horizontalArrangement =Arrangement.spacedBy(8.dp)
                    ){
                        TextButton(onClick = onDismiss) {
                            Text("取消")
                            onDismiss
                        }
                        TextButton(onClick = {onConfirm(text) } ,
                            enabled =text.isNotBlank()
                        ){
                            Text("确认")
                        }
                    }
                }
            }
        }
    }
}